#include "listitem.h"
#include "ui_listitem.h"
#include<QPushButton>
listitem::listitem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::listitem),
    islike(false)
{
    ui->setupUi(this);
    connect(ui->likeBtn,&QPushButton::clicked,this,&listitem::onthislike);
}

void listitem::enterEvent(QEvent *event)
{
    (void)event;
    setStyleSheet("background-color:#EFEFEF");
}

void listitem::leaveEvent(QEvent *event)
{
    (void)event;
    setStyleSheet("");
}

listitem::~listitem()
{
    delete ui;
}
void listitem::setMusicName(const QString &name)
{
    ui->musicNameLabel->setText(name);
}

void listitem::setSinger(const QString &singer)
{
    ui->musicSingerLabel->setText(singer);
}

void listitem::setAlbumName(const QString &albumName)
{
    ui->albumNameLabel->setText(albumName);
}

void listitem::onthislike()
{
    islike=!islike;
    setLikeIcon(islike);
    emit setIsLike(islike);
}

void listitem::setLikeIcon(bool like)
{
    islike=like;
    if(islike)
    {
        ui->likeBtn->setIcon(QIcon(":/images/like_2.png"));
    }
    else
    {
        ui->likeBtn->setIcon(QIcon(":/images/like_3.png"));
    }
}
